package com.hd123.rumba.gwt.widget.client.grid;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.HasAlignment;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.Widget;


public class HyperlinkRendererFactory extends CellRendererFactory implements HasHorizontalAlignment{

  public CellRenderer render(final DxGrid grid, final int row, final int col, final String text, final String width,
      final boolean readOnly, final boolean selected) {
    final HyperlinkRenderer widget = new HyperlinkRenderer();
    widget.setValue(text);
    grid.setWidget(row, col, widget);
    widget.setStyleName(selected ? selectedStyleName : styleName);
    widget.setWidth(width);
    grid.getCellFormatter().setHorizontalAlignment(row, col, align);
    widget.addClickListener(new ClickListener() {
      public void onClick(Widget sender) {
        grid.fireCellWidgetClick(grid, widget, row, col);
      }
    });
    return widget;
  }
  private HorizontalAlignmentConstant align = HasAlignment.ALIGN_LEFT;

  public HorizontalAlignmentConstant getHorizontalAlignment() {
    return align;
  }

  public void setHorizontalAlignment(HorizontalAlignmentConstant align) {
    this.align = align;
  }

}
